<#assign ctx=request.contextPath />
<#import '${ctx}/sys/include/head.html' as d/>
<#import '${ctx}/sys/include/body.html' as c/>
<#import '${ctx}/sys/include/table/toolbar.html' as t/>
<#import '${ctx}/sys/include/table/select.html' as select />
<!DOCTYPE html>
<html>
<head>
<@d.head title="spark配置" />
</head>
<@c.body>
<div class="layui-tab layui-tab-brief">
  <ul class="layui-tab-title">
    <li class="layui-this">spark管理器</li>
    <li>运行参数</li>
  </ul>
  <div class="layui-tab-content">
    <div class="layui-tab-item layui-show">
    	<table id="submitter_list" lay-filter="submitter_list"></table>
    </div>
    <div class="layui-tab-item">
		<div class="layui-form-item">
   			<label class="layui-form-label">请选择</label>
   			<div class="layui-input-block"><@select.table
		        name="id" show="name" title="ip"
		        url="${ctx}/biz/spark/conf/submitter/p/submitter-table" />
		    </div>
		</div>
    </div>
  </div>
</div>
</@c.body>
<script>
layui.use(['form','element','table','appJs'],function(){
	var form = layui.form
	,element = layui.element
	,table = layui.table
	,$=layui.$
	,app=layui.appJs;

	var tableOption = {
			id:'submitter_list'
			    ,elem: '#submitter_list'
			    //,height: 420
			    ,url: '${ctx}/biz/spark/conf/submitter/list' //数据接口
			    ,title: '配置表'
			    ,page: true //开启分页
			    ,toolbar: '#topBar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
			    ,cols: [[ //表头
			      {type: 'checkbox', fixed: 'left'}
			      ,{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
			      ,{field: 'name',width:100, title: '名称'}
			      ,{field: 'ip',title: 'IP地址'}
			      ,{field: 'port',title: '端口'}
			      ,{fixed: 'right',title:'操作', width:180, align:'center', toolbar: '#itemBar'}
			    ]]
	};
	table.render(tableOption);

	  table.on('toolbar(submitter_list)',function(obj){
		  var checkStatus = table.checkStatus(obj.config.id);
		  switch(obj.event){
		    case 'add':
		      var info_layer = layer.open({
		    	  type:2
		    	  ,title:'添加spark任务管理器'
		    	  ,maxmin: true//开启最大化最小化按钮
		    	  ,content:['${ctx}/biz/spark/conf/submitter/p/submitter_info']
		      	  ,success:function(layero, index){
		      			var iframeWin = window[layero.find('iframe')[0]['name']];
		      		}
		      	  ,end:function(){
		      		  table.reload('submitter_list',tableOption);
		      	  }

		      });
		      layer.full(info_layer);
		    break;
		    case 'delete':
		    	if(checkStatus.data.length<=0) {
		    		layer.msg("未选中删除行");
		    		return;
		    	}
	    		layer.confirm('确定删除吗？', function(index){
	    			var ids = [];
	  		      for(var r of checkStatus.data) {
	  		    	  ids.push(r.id);
	  		      }
	  		      $.ajax({
	  		    	  type:'post',
	  		    	  url:'${ctx}/biz/spark/conf/submitter/deletes',
	  		    	  data:{ids:ids},
	  		    	  traditional: true,
	  		    	  success:function(data){
	  		    		  if(data.code == 0) {
	  		    		  	layer.msg("删除成功");
	  		    		  	table.reload('submitter_list',tableOption);
	  		    		  }else {
	  		    			  layer.msg(data.code+":"+data.msg);
	  		    		  }
	  		    	  }
	  		      });
	    		});

		    break;
		  };
	  });

	  table.on('tool(submitter_list)',function(obj){
		  var data = obj.data; //获得当前行数据
		  var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		  var tr = obj.tr; //获得当前行 tr 的DOM对象

		  if(layEvent === 'detail'){ //查看
		    var layerIndex = layer.open({
		    	type:2
		    	,title:'任务管理器详情'
		    	,maxmin: true//开启最大化最小化按钮
		    	,content:['${ctx}/biz/spark/conf/submitter/p/submitter_info']
		      	,success:function(layero, index){
		      		var iframeWin = window[layero.find('iframe')[0]['name']];
		      		app.fillForm($(iframeWin.document).find('.layui-form'),'${ctx}/biz/spark/conf/submitter/find',data.id,layero);
		      		app.disableForm($(iframeWin.document).find('.layui-form'));
		      		//iframeWin.disableEdit();
		      	}
		    });
		    layer.full(layerIndex);
		  } else if(layEvent === 'del'){ //删除
		    layer.confirm('真的删除行么', function(index){
		    	$.ajax({
	  		    	  type:'post',
	  		    	  url:'${ctx}/biz/spark/conf/submitter/delete',
	  		    	  data:{id:data.id},
	  		    	  success:function(data){
	  		    		  if(data.code == 0) {
	  		    		  	layer.msg("删除成功");
	  		    		  obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
	  				      layer.close(index);
	  		    		  }else {
	  		    			  layer.msg(data.code+":"+data.msg);
	  		    		  }
	  		    	  }
	  		      });
		    });
		  } else if(layEvent === 'edit'){ //编辑
		    //do something
		    	  var info_layer = layer.open({
		    	  type:2
		    	  ,title:'修改'
		    	  ,maxmin: true//开启最大化最小化按钮
		    	  ,content:['${ctx}/biz/spark/conf/submitter/p/submitter_info']
		      	  ,success:function(layero, index){
		      		var iframeWin = window[layero.find('iframe')[0]['name']];
		      		$(iframeWin.document).find('.layui-form').append('<input name="id" type="hidden" />');
		      		app.fillForm($(iframeWin.document).find(".layui-form"),'${ctx}/biz/spark/conf/submitter/find',data.id,layero);
		      		iframeWin.layui.form.render();
		      		//iframeWin.disableEdit();
		      	  },
  		    	  end:function(){
		      		  table.reload('submitter_list',tableOption);
		      	  }
		      });
		      layer.full(info_layer);
		    //同步更新缓存对应的值
		    obj.update({
		      username: '123'
		      ,title: 'xxx'
		    });
		  }
	  });

	  document.addEventListener("select_table_ok",e=>{
		  console.log("xxx->"+e);
		  console.log(e.detail.co);
	  });
});
</script>
<@t.bar />
